var express = require('express');
const { MongoClient } = require('mongodb');
var router = express.Router();

//评论id
router.get('/commentId', function(req, res, next) {
  res.render('index', { title: 'Express' });
});
//评论内容
router.get('/commentText', function(req, res, next) {
  var userTxt = req.body
  MongoClient.connect(config.url,function(err,client){
    if(err){
      console.log('数据库连接失败',err)
      res.json({code:200,message:'error',data:err})
    }else{
      var db = client.db()
      var flag = false
      db.collection('comment').find({})
    }
  })
    if(flag){
      res.json({code:200,message:'ok',data:result[i]})
    }else{
      res.json({code:200,message:'error'})
    }
  });
//评价点赞
router.get('/commentThumbs', function(req, res, next) {
  var userThumbs = req.body
  MongoClient.connect(config.url,function(err,client){
    if(err){
      console.log('数据库连接失败',err)
      res.json({code:200,message:'error',data:err})
    }else{
      var db = client.db()
      var flag = false
      db.collection('comment').find({})
    }
  })
  if(flag){
    res.json({code:200,message:'ok',data:result[i]})
  }else{
    res.json({code:200,message:'error'})
  }
  });
//买家昵称
router.get('/commentNickname', function(req, res, next) {
  var userNickname = req.body
  MongoClient.connect(config.url,function(err,client){
    if(err){
      console.log('数据库连接失败',err)
      res.json({code:200,message:'error',data:err})
    }else{
      var db = client.db()
      var flag = false
      db.collection('comment').find({})
    }
  })
  if(flag){
    res.json({code:200,message:'ok',data:result[i]})
  }else{
    res.json({code:200,message:'error'})
  }
  });
module.exports = router;